using Microsoft.SemanticKernel;
using Microsoft.Extensions.DependencyInjection;

//Ai服务提供商注册
public abstract class AiProviderRegister
{
    public abstract EnumAiProviderType AiProviderType{get;}

    // 根据AiProvider 注入匹配的AI服务Kernel
    public virtual void Register(IServiceCollection service,AiProvider aiProvider)
    {

        service.AddKeyedTransient<Kernel>(aiProvider.Code, (provider,key)=>BindKernel(provider,aiProvider));
    } 

    //构建对应的AI服务Kernel

    public virtual Kernel BindKernel(IServiceProvider provider,AiProvider aiProvider)
    {
        //构件builder
        var builder= Kernel.CreateBuilder();


        RegisterChatCompletionService(builder,provider,aiProvider);
        RegisterEmbeddingService(builder,provider,aiProvider);

        //此处可以注入更多自定义的服务
        return builder.Build();
    }

    //注册聊天补全服务
    protected abstract void RegisterChatCompletionService(IKernelBuilder builder,IServiceProvider provicer,AiProvider aiProvider);
    //注册文本嵌入服务
     protected abstract void RegisterEmbeddingService(IKernelBuilder builder,IServiceProvider provicer,AiProvider aiProvider);

}